import React, { Component } from 'react';
import { Image } from "react-native";
import ValidateDataUtil from '../utils/ValidateDataUtil';
import { GLOBAL } from '../config/global';

const defaultLogo = require('../imgs/customer/office.png');
const scale = GLOBAL.SCALE;

export default class LogoComponent extends Component {

	constructor(props) {
		super(props);
		this.state = {
			onError: false
		}
	}

	render () {
		const { logoPath, height, width } = this.props;
		const logo = (this.state.onError) ? defaultLogo : (ValidateDataUtil.isEmpty(logoPath)) ? defaultLogo : { uri: logoPath };;
		const style = { height: height * scale, width: width * scale, };

		return (
			<Image source={logo} style={style}
				onError={() => {
					this.setState({
						onError: true
					});
				}} />
		);
	}

}
